home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / addr / fullparse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-11  |  2.2 KB  |  93 lines

  1. #include "ap_lex.h"
  2. #include "util.h"
  3. #include "ap.h"
  4.  
  5. /*  Build full parse tree from an address list                            */
  6.  
  7. /*  I expect this not to be used very often, but it was convenient to
  8.     provide and will work just fine when there are small address
  9.     lists.
  10.  
  11.     It repeatedly invokes ap_1adr to acquire address segments, linking
  12.     them together and NXT's.
  13.  
  14. */
  15.  
  16. /*  < 1978  B. Borden       Wrote initial version of parser code
  17.  *  78-80   D. Crocker      Reworked parser into current form
  18.  */
  19. extern AP_ptr ap_pcur,    /* Current ap node ptr              */
  20.           ap_pstrt;   /* Beginning of parse tree          */
  21.  
  22. #if DEBUG > 1
  23. extern int debug;          /* True if in debug mode                */
  24. extern char *statnam[],
  25.            *ptrtab[],
  26.            *typtab[];
  27. #endif
  28.  
  29. /* */
  30.  
  31. AP_ptr
  32. ap_fullparse (gchfunc)
  33. char    (*gchfunc) ();
  34. {
  35.     AP_ptr    ap_fp;        /* Beginning of list                    */
  36.     char    more;
  37.     register AP_ptr ap_sp, ap_prevp = NULL;
  38.     int    naddrs = 0;
  39.  
  40.     ap_fp = ap_pinit (gchfunc);
  41.     more = 0;
  42.     for (;;)
  43.     {
  44.         ap_sp = ap_pcur;
  45.         switch (ap_1adr ()) {
  46.         case NOTOK: 
  47.             return ((AP_ptr)NOTOK);
  48.         case DONE: 
  49.             if (--more > 0)   /* > 0 means files are stacked          */
  50.                 ap_fpop (); /* just drop on through                 */
  51.             else if (naddrs)
  52.                 return(ap_fp);
  53.             else
  54.                 return ((AP_ptr)DONE);
  55.         case OK: 
  56.             naddrs++;
  57.             switch (ap_sp -> ap_obtype) {
  58.             case APV_DTYP: 
  59.                 if (lexequ ("Include", ap_sp -> ap_obvalue))
  60.                 {      /* indirect through a file              */
  61. #if DEBUG > 1
  62.                 if (debug)
  63.                     printf ("(File:%s)",
  64.                         ap_sp -> ap_chain -> ap_obvalue);
  65. #endif
  66.                 if (ap_fpush (ap_sp -> ap_chain -> ap_obvalue)
  67.                     != OK)
  68.                     return ((AP_ptr)NOTOK);
  69.                 more++;
  70.                 if ((ap_pcur = ap_sqdelete (ap_sp, ap_pcur)) == 0)
  71.                     ap_palloc ();
  72.                 else
  73.                     ap_pnsrt (ap_alloc (), APP_NXT);
  74.                 if (ap_fp == ap_sp)
  75.                     ap_fp = ap_pcur;
  76.                 if (ap_prevp != ap_sp)
  77.                     ap_prevp -> ap_chain = ap_pcur;
  78.                 continue;
  79.                 }
  80.             default:
  81. #if DEBUG > 1
  82.                 printf ("[Got an address]\n", ap_pcur);
  83. #endif
  84.                 ap_pcur -> ap_ptrtype = APP_NXT;
  85.                 ap_prevp = ap_pcur;
  86.                 ap_pstrt = ap_pcur = ap_alloc();
  87.                 ap_prevp -> ap_chain = ap_pstrt;
  88.                 continue;
  89.             }
  90.         }
  91.     }
  92. }
  93.